﻿using System;
using System.Collections.Generic;
using SilveR.Views.StatsViews;
using System.Windows;

namespace SilveR.DataValidators
{
    public class NonParametricsValidator : DataValidator
    {
        private readonly NonParametricVariables npVariables;

        public NonParametricsValidator(NonParametricVariables np)
            : base(np.SelectedDataHandler)
        {
            npVariables = np;
        }

        public override bool Validate()
        {
            //go through all the column names, if any are numeric then stop the analysis
            List<string> allVars = new List<string>();
            allVars.Add(npVariables.Treatment);
            allVars.Add(npVariables.Response);
            if (!CheckColumnNames(allVars)) return false;

            if (!CheckIsNumeric(npVariables.Response))
            {
                MessageBox.Show("Error: The response selected contain non-numeric data that cannot be processed. Please check the raw data and make sure the data was entered correctly.", "Validate Data", MessageBoxButton.OK);
                return false;
            }

            if (!CheckTreatmentsHaveLevels(npVariables.Treatment)) return false;

            if (!CheckResponsesPerLevel(npVariables.Treatment, npVariables.Response)) return false;

            //check response and treatments contain values
            if (!CheckResponseAndTreatmentsNotBlank(npVariables.Response, npVariables.Treatment, "treatment factor")) return false;

            //if only two levels and all treats or to control selected, then need to only do KW
            if (CountDistinctLevels(npVariables.Treatment) == 2 && npVariables.AnalysisType != SilveR.Views.StatsViews.NonParametricVariables.AnalysisOption.MannWhitney)
            {
                string message = "The treatment factor selected has only two levels so a Mann-Whitney test is presented.";
                WarningMessages.Add(message);
            }

            //if get here then no errors so return true
            return true;
        }
    }
}